//
//  ZPMainViewController.swift
//  Weibo
//
//  Created by 张鹏 on 16/6/23.
//  Copyright © 2016年 张鹏. All rights reserved.
//

import UIKit

class ZPMainViewController: UITabBarController {

    override func viewDidLoad() {
        

        
        super.viewDidLoad()
        //自动以tabBar
        let tabBar = ZPTabBar()
        //设置代理
        tabBar.zpDelegate = self
        //通过KVC 给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        addChildViewController(ZPHomeTableViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(ZPMessageTableViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(ZPDiscoverTableViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(ZPProfleTableViewController(), title: "我", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(vc: UIViewController,title: String,imgName: String) {
        //设置title
        vc.title = title
        //tabbar_home_selected
        //设置image
        vc.tabBarItem.image = UIImage(named: imgName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        let navC = UINavigationController(rootViewController: vc)
        addChildViewController(navC)
    
    }

}

extension ZPMainViewController:ZPTabBarDelegate{
    func composeButtonClick() {
        print("弹出控制器")
        let nav = UINavigationController(rootViewController: ZPComposeViewController())
        presentViewController(nav, animated: true, completion: nil)
    }
}
